<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
</head>

<body>
    <input type="button" value="点击我开启倒计时获取验证码">

    <script>
        $(function () {
            var num = 5
            var flag = true
            var  timer=null
            $('input').on('click', function () {

                if (flag) {
                    console.log(111111111);
                    timer=setInterval(() => {
                        flag = false
                        num--
                        $('input').val(num)
                        if (num < 0) {
                            $('input').val('点击我开启倒计时获取验证码')
                            flag = true
                            num=5
                            clearInterval(timer)
                        }
                    }, 1000)

                }

            })
        })
    </script>
</body>

</html>